package ms.jacrim.framework;

import java.io.Serializable;
import java.util.Date;


public class Event implements Serializable {

	private static final long serialVersionUID = 1L;

	private Date start, end;
	private String title, description;
	
	private ActiveSolution.ActionInfo info;
	
	public Event() {

	}
	
	public Event(ActiveSolution.ActionInfo info) {
		this.info = info;
	}
	
	public Event(String title) {
		this.title = title;
		start = end = new Date();
	}
	
	public Date getStart() {
		return info != null ? info.getStart() : start;
	}

	public void setStart(Date start) {
		this.start = start;
	}

	public Date getEnd() {
		Date result = end != null ? end : info != null ? info.getEnd() : null;
		return result;
	}

	public Date getResolvedEnd(boolean defaultIsNow) {
		Date result = end != null ? end : info != null ? info.getEnd() : null;
		return result != null ? result : defaultIsNow ? new Date() : start;
	}
	
	public void setEnd(Date end) {
		this.end = end;
	}

	public boolean isFinished() {
		return end != null || (info != null && info.getEnd() != null);
	}
	
	public String getTitle() {
		return title != null ? title : info != null ? info.getTitle() : "";
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public ActiveSolution.ActionInfo getActionInfo() {
		return info;
	}

	public void setActionInfo(ActiveSolution.ActionInfo actionInfo) {
		info = actionInfo;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}


}
